from django.db import models
import django.utils.timezone as timezone


# Create your models here.

class module_manager(models.Model):
    NAME = models.CharField('模块名称', max_length=32, unique=True)
    IN_PARA_COMMENT = models.CharField('输入参数描述', max_length=1024)
    PRO_STATUS = models.BooleanField('模块状态', default=True)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.NAME


class version_manager(models.Model):
    VERSION = models.CharField('大版本号', max_length=32)
    IN_PARA_COMMENT = models.CharField('输入参数描述', max_length=1024)
    PRO_STATUS = models.BooleanField('发布状态')
    MODULE_NAME = models.ForeignKey(to=module_manager, to_field="NAME", on_delete=models.CASCADE,
                                    verbose_name="模块名称", null=True)
    MODULE_VERSION = models.CharField('模块版本号', max_length=32)
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)

    class Meta:
        unique_together = (("VERSION", "MODULE_NAME"),)


class deployment(models.Model):
    DEPLOY_STATUS = models.BooleanField('发布状态', default=False)
    MODULE_INFO = models.CharField('模块名称', max_length=32)
    BIG_VERSION = models.CharField('大版本号', max_length=32)
    MODULE_VERSION = models.CharField('模块版本号', max_length=32)
    TIME_TYPE_STATUS_CHOICES = (
        ("01", '上午'),
        ("02", '中午'),
        ("03", "下午")
    )
    DEPLOY_TIME = models.CharField('发布时间', max_length=32, choices=TIME_TYPE_STATUS_CHOICES, default="03")
    create_time = models.DateTimeField(auto_now_add=True)
    update_time = models.DateTimeField(auto_now=True)


class taskAPS(models.Model):
    JOB_ID = models.CharField('任务ID', max_length=32)
    Cron_TIME = models.CharField('任务时间', max_length=256)
    Cron_STATUS = models.BooleanField('任务状态', default=False)


class job_detail(models.Model):
    JOB_TYPE_STATUS_GP = '01'
    JOB_TYPE_STATUS_DEFAULT = '02'
    JOB_TYPE_STATUS_CHOICES = (
        (JOB_TYPE_STATUS_GP, 'Greenplum函数'),
        (JOB_TYPE_STATUS_DEFAULT, '其他'),
    )

    CREATED_BY = models.CharField('创建人', max_length=32)  # 创建人
    CREATED_TIME = models.DateTimeField('创建时间', default=timezone.now)  # 创建时间
    UPDATED_BY = models.CharField('更新人', max_length=32)  # 更新人
    UPDATED_TIME = models.DateTimeField('更新时间', default=timezone.now)  # 更新时间
    JOB_TYPE = models.CharField('任务类型', max_length=32,
                                choices=JOB_TYPE_STATUS_CHOICES,
                                default=JOB_TYPE_STATUS_DEFAULT
                                )  # 任务类型 01：gp任务；02：datax任务；03：kafka推送任务；04：http请求任务
    JOB_NAME = models.CharField('任务名称', max_length=128)  # 任务名称
    JOB_COMMENT = models.CharField('任务描述', max_length=128)  # 任务描述
    IN_PARA = models.CharField('输入参数定义', max_length=32)  # 输入参数定义 参数使用英文逗号分隔
    IN_PARA_COMMENT = models.CharField('输入参数描述', max_length=1024)  # 输入参数描述
    OUT_PARA = models.CharField('输出参数定义', max_length=32)  # 输出参数定义 参数使用英文逗号分隔
    OUT_PARA_COMMENT = models.CharField('输出参数描述', max_length=1024)  # 输出参数描述
    VERSION = models.CharField('版本号', max_length=32)  # 版本号
    IS_DELETE = models.CharField('是否删除', max_length=1, default='N')  # 逻辑删除 Y:删除；N:正常
    PRO_STATUS = models.CharField('发布状态', max_length=1, default='N')  # 发布状态 Y:发布；N:开发
